
package com.zhongketech.sunflower.utils;

import android.graphics.Bitmap;
import android.text.TextUtils;

/**
 * 异步读取本地图片并显示
 * 
 * @author 906707
 * @version [版本号, 2013年11月25日]
 * @since [产品/模块版本]
 */
public class AsyncImageLoader {

    private static AsyncImageLoader mInstance = null;

    private static Object object = new Object();

    public static AsyncImageLoader getInstance() {
        if (mInstance == null) {
            synchronized (object) {
                mInstance = new AsyncImageLoader();
            }
        }
        return mInstance;
    }

    /**
     * ImageView 异步加载图片
     * 
     * @param imgView
     * @param localPath
     * @param width
     * @param height
     * @param defaultResId 默认图片
     * @param imageCallBack [参数说明]
     * @return void [返回类型说明]
     * @exception throws [违例类型] [违例说明]
     */
    public void loadLocalBitmap(final boolean focus, final String localPath,
            final int width, final int height, final ImageCallBack imageCallBack) {
        if (imageCallBack == null || TextUtils.isEmpty(localPath)) {
            return;
        }

        // 加载本地图片
        new UserTask<String, Void, Bitmap>() {
            @Override
            public Bitmap doInBackground(String... arg0) {
                Bitmap bitmap = ImageUtil.decodeSampledBitmapFromFile(
                        localPath, width, height);
                return bitmap;
            }

            @Override
            public void onPostExecute(Bitmap result) {
                imageCallBack.imageLoad(result);
            }
        }.execute(localPath);
    }

    /**
     * CallBack:显示图片
     */
    public interface ImageCallBack {
        public void imageLoad(Bitmap bitmap);
    }

}
